
//判断用户登陆后，如果在frame子页面内session超时将返回父页面登陆页面
function  returnLoginPage(){			
	var selfUrl = self.location+"";
	var topUrl = top.location+"";				
	var arr=new Array();	
	arr=selfUrl.split("/");	
	if(arr.length>0){
		var lastNode=arr[arr.length-1];			
		if(lastNode =="admin_index.jsp" && selfUrl != topUrl){	
			top.location.href='admin_index.jsp';
		}
	}
}
		

//显示模态窗口
function lockedPage()
{
   var a = "webimg/loading.gif";
   var floatDiv = window.document.createElement("div");
   var width = window.document.body.clientWidth;
   var height= window.document.body.clientHeight;
   with(floatDiv) {
	  id  = "floatDiv";
      style.cssText = "Z-INDEX: 500; LEFT: 0px; WIDTH: "+ width +"px; POSITION: absolute; TOP: 0px; HEIGHT: "+ height +"px; border:1px solid #E7EFEF; background-color:#E7EFEF;filter:alpha(opacity=85);";
      innerHTML="<div style='float:left;position:fixed;_position:absolute;left:38%;top:42%;' align='center'><center><img src='"+a+"' style='margin-right:8px;float:left;vertical-align:top;'/></center></div><div style=position:absolute;left:40%;top:49%><font color='blue' size='3px'>请稍后...</font></div>";
   }
   window.document.body.appendChild(floatDiv);
}

//去除模态窗口
function unlockPage(){
	var div1=window.document.getElementById('floatDiv');
	window.document.body.removeChild(div1);
}

//登陆js
function loginPage() {	
	var isTrue;
	var userName=$("#userName").val();
	var userPassword=$("#userPassword").val();
	if(""==userName || ""==userPassword){
	 	alert("帐号和密码不能为空");
	}else{
	    lockedPage();
		url = "login_login?userName="+encodeURI(encodeURI(userName))+"&userPassword="+userPassword;
		var str= "a=" + Math.random() * 1000;
		url=url+"&"+str; 
		$.post(url,null,function(data){
			if(data != 'OK'){
				unlockPage();
				alert(data);
			}else{			
				subCookie();
				window.location="adminmgr/mgrMain.jsp?"+str;
			}
        }, "text");
	}
}

//回车提交事件
document.onkeydown = function(e){
    if(!e) e = window.event;//火狐中是 window.event
    if((e.keyCode || e.which) == 13){
        loginPage();
    }
}

//设置图片滚动
function scrollPhoto(){
	var time = null;
	var ul = document.getElementById("wrap").getElementsByTagName("ul")[0];
    var lis = ul.getElementsByTagName("li");
    var btn1 = document.getElementById("button1");
    var btn2 = document.getElementById("button2");
    var imgs = ul.getElementsByTagName("img");
    var speed = 3;            
    //ul.innerHTML += ul.innerHTML;
    ul.style.width = (lis[0].offsetWidth+20)*lis.length + "px";
    time = setInterval(usePhoto,30);
    btn1.onmouseover = function(){
        speed = 3;
    }
    btn2.onmouseover = function(){
        speed = -3;
    }
    for(var i in imgs){
        imgs[i].onmouseover = function(){
            clearInterval(time);
            for(var i = 0;i<imgs.length;i++){
                imgs[i].className = "none";
            }
            this.className = "active";
        }
        imgs[i].onmouseout = function(){
            time = setInterval(usePhoto,30);
            for(var i = 0;i<imgs.length;i++){
                imgs[i].className = "none";
            }
        }
   	}
}

//装载需要滚动的文件 
function usePhoto(){
	var ul = document.getElementById("wrap").getElementsByTagName("ul")[0];
	var speed = 3;
    ul.style.left = ul.offsetLeft - speed + "px";
    if(ul.offsetLeft <= -ul.offsetWidth/2){
       ul.style.left ="0px";
    }else if(ul.offsetLeft >=0){
       ul.style.left = -ul.offsetWidth/2 + "px";
    }
}

//此处增加cookie--------------------------------------------------------------------------------------------------------------------------------
//添加cookie
function addCookie(objName,objValue,objDays){
	var str = objName + "=" + escape(objValue);
	if(objDays > 0){//为0时不设定过期时间，浏览器关闭时cookie自动消失
		var date = new Date();
		var ms = objDays * 24 * 60 * 60 * 1000;
		date.setTime(date.getTime() + ms);
		str += "; expires=" + date.toGMTString();
	}
	document.cookie = str;
}

//获取指定名称的cookie的值
function getCookie(objName){
	var cookie_val="";
	var arrStr = document.cookie.split("; ");
	for(var i = 0;i < arrStr.length; i++){
		var temp = arrStr[i].split("=");
		if(temp[0] == objName){ 
			cookie_val = unescape(temp[1]);
			break;
		}
	} 
	return cookie_val;
}

//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
function delCookie(name){
	var date = new Date();
	date.setTime(date.getTime() - 10000);
	document.cookie = name + "=a; expires=" + date.toGMTString();
}

//选中增加COOKIE|未选中删除cookie
function subCookie(){
	//var remindPass=loginForm.remindPassword;
	var remindPass=document.getElementById("remindPassword");
	if(remindPass!=null){
		//选中记住密码
		if(remindPass.checked){		
			var cookie_name = document.getElementById("userName").value;
			var cookie_value = document.getElementById("userPassword").value;
			var cookie_expireDays = 30;      //天
			addCookie(cookie_name,cookie_value,cookie_expireDays);
		}else{   //没选中删除之前记住的cookie
			del_();
		}
	}
}


//选中增加COOKIE
function add_(){			
	var cookie_name = document.getElementById("userName").value;
	var cookie_value = document.getElementById("userPassword").value;
	var cookie_expireDays = 30;      //单位：天
	addCookie(cookie_name,cookie_value,cookie_expireDays);
}

//查询对应的cookie
function get_(){
	var cookie_name = document.getElementById("userName").value;
	var cookie_value = getCookie(cookie_name);
	if(cookie_value != null && cookie_value != ""){
		document.getElementById("userPassword").value=cookie_value;
		document.getElementById("remindPassword").checked=true;
	}
}

//删除对应的cookie
function del_(){
	var cookie_name = document.getElementById("userName").value;
	delCookie(cookie_name);
}


